"use strict";

const Transaction = require("sequelize").Transaction;
const { sequelize, User, UserCheckin } = require("./index");


// 事务
sequelize
  .transaction(t =>
    User.create(
      {
        username: "itbilu",
        password: "pwd",
        active: true
      },
      { transaction: t }
    ).then(user =>
      UserCheckin.create(
        {
          userId: user.id,
          loginIp: "127.0.0.1"
        },
        { transaction: t }
      )
    )
  )
  .then(res => {
    // do something when the response is successful
  })
  .catch(err => {
    // do something when error
  });
